#ifndef ROS2_GUI_BRIDGE_ROS2_GUI_BRIDGE_NODE_HPP_
#define ROS2_GUI_BRIDGE_ROS2_GUI_BRIDGE_NODE_HPP_

#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/float32_multi_array.hpp>
#include <sensor_msgs/msg/joint_state.hpp>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <cstring>
#include <iostream>
#include <thread>
#include <vector>
#include <yaml-cpp/yaml.h>

// 将 BUFFER_SIZE 定义为 128
constexpr size_t BUFFER_SIZE = 128;

typedef struct {
    float target_position;
    float actual_position;
    float target_velocity;
    float actual_velocity;
    float target_force;
    float actual_force; 
    float position_error;
    float force_error;
    float stator_current;
    float supply_voltage;
    float motor_temp;
    float transistor_temp;

    float error_code;
    int motor_mode;
} motor_t;

typedef struct {
    float preTOR;
    float preVEL;
    float prePOS;

    float actTOR;
    float actVEL;
    float actPOS;  
} joint_t;

typedef struct {
    float x;
    float y;
    float z;
} sensor_t;

// 函数声明
void float2uchar(float value, unsigned char* buffer);
void convertFloatVectorToHex(const std::vector<float>& floatVector, unsigned char* charArray);
void chksum(unsigned char* arr, size_t len);
float uchar2float(const unsigned char* buffer);
void motor_controllers_callback(const std_msgs::msg::Float32MultiArray::SharedPtr msg);
void joint_status_callback(const sensor_msgs::msg::JointState::SharedPtr msg);
void sensor_status_callback(const std_msgs::msg::Float32MultiArray::SharedPtr msg);
void send_messages(const std::string& target_ip, int target_port);
void signal_handler(int signum);

#endif  // ROS2_GUI_BRIDGE_ROS2_GUI_BRIDGE_NODE_HPP_
    